// /*
//  * @Author: WanYiMing
//  * @Date:2024-05-24-15:09
//  * @Description:
//  */

using System.Collections.Generic;
using System.Linq;
using Code.DataManager.Converter;
using Code.DataManager.Model;
using Code.GameLogic.BaseClass.Model;
using Code.GameLogic.Map;
using Code.GameLogic.Monster;
using Code.GameLogic.XianJian;
using Code.GameLogic.XianJian.UI;
using QFramework;

namespace Code.DataManager
{
    public class SettingBo : AbstractModel
    {
        private readonly Dictionary<string, MonsterBo> _monsterBos = new Dictionary<string, MonsterBo>();
        private readonly Dictionary<string, XianJianUIBo> _xianJianUIList = new Dictionary<string, XianJianUIBo>();
        private readonly Dictionary<string, XianJianBo> _xianJianBos = new Dictionary<string, XianJianBo>();

        private MonsterFlashPointBo _monsterFlashPoint;
        private MapBo _mapBo;

        public MapBo MapBo
        {
            get => _mapBo;
            set => _mapBo = value;
        }

        public Dictionary<string, MonsterBo> MonsterBos => _monsterBos;

        public Dictionary<string, XianJianUIBo> XianJianUIList => _xianJianUIList;

        public Dictionary<string, XianJianBo> XianJianBos => _xianJianBos;


        public MonsterFlashPointBo MonsterFlashPoint
        {
            get => _monsterFlashPoint;
            set => _monsterFlashPoint = value;
        }


        protected override void OnInit()
        {
            _mapBo = LoadJsonBo(new MapConvertImpl(), "\\地图.json");
            
            MonsterJsonBo monsterJsonBo = LoadJsonBo(new MonsterConvertImpl(), "\\怪兽.json");
            SetMonster(monsterJsonBo.monsterList);
            SetMonsterFlashPoint(monsterJsonBo.flashPointSetting);
            
            LoadJsonBo(new XianJianConvertImpl(), "\\仙剑.json",_xianJianBos);
            
            LoadJsonBo(new XianJianUIConvertImpl(), "\\仙剑UI列表.json",_xianJianUIList);

            
        }

    

        #region 数据加载
        
        private void SetMonsterFlashPoint(MonsterJsonBo.FlashPointSetting flashPointSetting)
        {
            _monsterFlashPoint = new MonsterFlashPointBo();
            _monsterFlashPoint.FlashSpeed = flashPointSetting.flashSpeed;
            _monsterFlashPoint.Rate = flashPointSetting.rate;
            _monsterFlashPoint.MonsterPoll = flashPointSetting.monsterPoll;
        }

        private void SetMonster(MonsterJsonBo.Monster[] monsterList)
        {
            for (int i = 0; i < monsterList.Length; i++)
            {
                var monster = monsterList[i];
                MonsterBo monsterBo = new MonsterBo(new BaseDescription(monster.type, monster.name));
                monsterBo.Hp = monster.hp;
                monsterBo.Speed = monster.speed;
                monsterBo.ResourceRate = monster.resourceRate;
                _monsterBos[monster.type] = monsterBo;
            }
        }

        #endregion

        public T LoadJsonBo<T, TV>(ISettingConvert<T, TV> settingConvert, string jsonPath)
        {
            var blockJsonBoForJson = DataForJson.GetBlockJsonBoForJson<TV>(jsonPath);
            var convertToBo = settingConvert.ConvertToBo(blockJsonBoForJson);
            return convertToBo;
        }
        
        public T LoadJsonBo<T, TV>(ISettingConvert<T, TV> settingConvert, string jsonPath,T result)
        {
            var blockJsonBoForJson = DataForJson.GetBlockJsonBoForJson<TV>(jsonPath);
            var convertToBo = settingConvert.ConvertToBo(blockJsonBoForJson,result);
            return convertToBo;
        }
        
    }
}